function twoSum1(nums: number[], target: number): number[] {
    let start = 0;
    let end = 0;
    for (let i = 0; i < nums.length; i++){
        for (let j = 0;j< nums.length; j++){
            if(nums[j]+nums[i] ===  target&&i!==j){ 
                if(i>j){
                    start = j;
                    end = i; 
                } else{
                    start = i;
                    end = j;
                }
            }
        }
    }
    return [start, end];
};

// 最费劲的方式 两次循环一个个找然后找出索引

function twoSum(nums: number[], target: number): number[] {
    for (var i = 0; i < nums.length; i++){
        const temp = nums.findIndex((item)=> item+ nums[i] === target);
        if(temp !== -1 && temp !== i){
            if(i<temp){
                return[i,temp]
            } else {
                return[temp,i]
            }
        }
    }
};

// 使用数组所含方法 费时内存用的较少


const nums = [2,7,11,15], target = 9;
console.log(twoSum(nums, target));